/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utility;

import java.net.Socket;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 *
 * @author Leenix
 */
public class ChatServerTest {

    ChatServer server = new ChatServer();
    private Socket clientSocket;
    String SPLIT_CHAR = server.getSplitChar();
    int portNumber = 49222;
    int delayTime = 100;

    public ChatServerTest() {
    }

    @Test
    /**
     * testIsValidPort_01 Test if the isValidPort method functions for valid
     * port numbers.
     */
    public void testIsValidPort_01() {
        int port = 50000;
        boolean result = server.isValidPortNumber(port);
        boolean expected = true;
        assertEquals(expected, result);
    }

    @Test
    /**
     * testIsValidPort_02 Test if the isValidPort method functions for invalid
     * port numbers.
     */
    public void testIsValidPort_02() {
        int port = 42;
        boolean result = server.isValidPortNumber(port);
        boolean expected = false;
        assertEquals(expected, result);
    }

    @Test
    /**
     * testStart Test if the server starts correctly and begins its listener
     * thread.
     */
    public void testStart() throws InterruptedException {
        server.setPortNumber(portNumber);
        server.start();

        // Give time for listener thread to start running.
        Thread.sleep(delayTime);
        assertEquals(true, server.isRunning());

        server.stop();
    }

    @Test
    /**
     * testStopServer_01 Test if the server stops correctly. Test 1 checks
     * whether the listener thread shuts down correctly or not.
     */
    public void testStopServer_01() throws InterruptedException {
        server.setPortNumber(portNumber);
        server.start();

        Thread.sleep(delayTime);
        server.stop();

        assertEquals(false, server.isRunning());
    }
    
    @Test
    public void testEncrypt(){
    	//TODO Test encryption
    	
    }

}
